﻿using AutoMapper;
using MediatR;
using S_Userinfor.Domains;
using S_UserInfor.Api.Application.Commands;
using S_UserInfor.Infrasturctre.Interface;

namespace S_UserInfor.Api.Application.CommandsHanders
{
    public class UserSqlSuageCeateCommandsHanders : IRequestHandler<UserSqlSuageCeateCommands, int>
    {
        private readonly IUserRepository _user;
        private readonly IMapper _mapper;

        public UserSqlSuageCeateCommandsHanders(IUserRepository user, IMapper mapper)
        {
            _user = user;
            _mapper = mapper;
        }

        public async Task<int> Handle(UserSqlSuageCeateCommands request, CancellationToken cancellationToken)
        {
           var res = _mapper.Map<User>(request);
           return await _user.AddAsync(res);
        }
    }
}
